﻿/*需要引用jquery,jqgrid等类库*/
var jgGridjsonReader = { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, cell: "cell", id: "Id", userdata: "userdata", subgrid: { root: "rows", repeatitems: true, cell: "cell"} };
function InitJQGrid(GridId, Options) {
    var defaultOptions = {
        datatype: 'json',
        rownumbers: true,
        cellsubmit: 'clientArray',
        shrinkToFit: false,
        width: "100%",
        loadonce:false,
        height: "200",
        rowNum: 20, //每页显示记录数 
        viewrecords: true, //是否显示行数 
        rowList: [10, 20, 30], 
        pager: '#gridpager' + GridId,
        jsonReader: jgGridjsonReader
    };
    $.extend(defaultOptions, Options);
    if (defaultOptions.height && parseFloat(defaultOptions.height) < 0) {
        var wh = GetInnerHeight();
        defaultOptions.height = parseFloat(wh) + parseFloat(defaultOptions.height);
    }
    if (defaultOptions.width && defaultOptions.width < 0) {
        var ww = GetInnerWidth();
        defaultOptions.width = ww + defaultOptions.width;
    }
    var grid = jQuery("#" + GridId).jqGrid(defaultOptions);
    if (defaultOptions.width == "100%" || defaultOptions.width == "auto")
        grid.setGridWidth(GetInnerWidth() - 5);

}